<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="test"></div>
    <script src="./js/react.development.js"></script>
    <script src="./js/react-dom.development.js"></script>
    <script src="./js/babel.min.js"></script>
    <script type="text/babel">
    // 生命周期回调函数 生命周期钩子函数
        class Life extends React.Component {
            state = {opcity:1}
            death = ()=>{
                
                ReactDOM.unmountComponentAtNode(document.getElementById("test"))
            }
            // 组件挂载完毕之后
            componentDidMount(){
                this.timer = setInterval(()=>{
                    let {opcity} = this.state
                    opcity > 0 ? opcity -= 0.1 : opcity = 1
                    this.setState({opcity})
                },200)
            }
            // 组件将要卸载
            componentWillUnmount(){
              clearInterval(this.timer)  
            }
            // render调用的时机是两个：初始化、渲染状态更新之后
            render() {
                return (
                    <div>
                        <h2 style={{opcity:this.state.opcity}}>React学不会怎么办？</h2>
                        <button onClick={this.death}>不活了</button>    
                    </div>
                )
            }
        }
        ReactDOM.render(<Life/>,document.getElementById("test"))
    </script>
</body>
</html>